<?php
namespace Admin\Model;
use Think\Model;


class ProfessionModel extends Model {

    public function getAllProfessionByDid($did) {
        $map['department_id'] = $did;
        return $this->where($map)->select();
    }


    public function getProfessionById($id) {
        return $this->find($id);
    }


    public function getProfessionName($id) {
        return $this->where('id = ' . $id)->getField('name');
    }

    public function getDepartmentId ($id) {
        return $this->where('id = '.$id)->getField('department_id');
    }


    /**
     * 根据院系ID, 获取该院系所有专业ID
     * @param $did
     * @return array
     */
    public function getAllPidByDid($did) {
        $map['department_id'] = $did;
        $res = $this->where($map)->select();

        $pids = array();
        foreach ($res as $val) {
            array_push($pids,$val['id']);
        }

        return $pids;
    }


    public function _add($data) {
        $map['name'] = $data['name'];
        $p = $this->where($map)->find();
        if (!empty($p)) return '100501';

        $flag = $this->add($data);
        if ($flag !== false) return '000000';
        return '111111';
    }


    public function _edit($data) {

        $map['name'] = $data['name'];
        $map['id'] = array('neq',$data['id']);
        $p = $this->where($map)->find();
        if (!empty($p)) return '100501';

        $flag = $this->save($data);
        if ($flag !== false) return '000000';
        return '111111';

    }


    public function _del($id) {
        $flag = $this->delete($id);
        if ($flag !== false) return '000000';
        return '111111';
    }


}